package gameressources;

public class RockPaperScissors {
	public Result play(RPSEnum player1, RPSEnum player2) {
		switch (player1) {
		case PAPER:
			switch (player2) {
			case PAPER:
				return Result.TIE;
			case ROCK:
				return Result.WIN;
			case SCISSORS:
				return Result.LOST;
			default:
				return Result.LOST;

			}
		case ROCK:
			switch (player2) {
			case PAPER:
				return Result.LOST;
			case ROCK:
				return Result.TIE;
			case SCISSORS:
				return Result.WIN;
			default:
				return Result.LOST;

			}

		case SCISSORS:
			switch (player2) {
			case PAPER:
				return Result.WIN;
			case ROCK:
				return Result.LOST;
			case SCISSORS:
				return Result.TIE;
			default:
				break;
			}

		default:
			return Result.LOST;

		}

	}

	public Result play(Player player1, Player player2) {

		for (int i = 0; i < player1.getRPSEnumLength(); i++) {
			switch (play(player1.getNextMove(), player2.getNextMove())) {
			case WIN:
				player1.setScore(player1.getScore() + 1);
				break;
			case TIE:
				player1.setScore(player1.getScore() + 1);
				player2.setScore(player2.getScore() + 1);
				break;
			case LOST:
				player2.setScore(player2.getScore() + 1);
				break;
			default:
				break;

			}
		}
		if (player1.getScore() > player2.getScore())
			return Result.WIN;
		else if (player1.getScore() == player2.getScore())
			return Result.TIE;
		else
			return Result.LOST;

	}
}
